package qsoft.com.tp51_sn_module

import android.annotation.SuppressLint
import android.os.Build
import android.util.Log

class TP51_SN {
    /**
     * 读取机器的序列号
     */
    @SuppressLint("MissingPermission")
    fun getSerialNumber(): String {
        var result = ""

        try {
            result = when {
                Build.VERSION.SDK_INT >= Build.VERSION_CODES.P -> {//9.0+
                    Build.getSerial()
                }
                Build.VERSION.SDK_INT > Build.VERSION_CODES.N -> {//8.0+
                    Build.SERIAL
                }
                else -> {//8.0-
                    val c = Class.forName("android.os.SystemProperties")
                    val get = c.getMethod("get", String::class.java)
                    get.invoke(c, "ro.serialno") as String
                }
            }
        } catch (e: Exception) {
            e.printStackTrace()
            Log.v("q-soft", e.message!!)
        }
        return result
    }
}